package com.mf.controller.pageConfig;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mf.entity.bo.pageConfig.BasicPageBo;
import com.mf.entity.request.pageConfig.PageBoAddReq;
import com.mf.entity.request.pageConfig.PageBoSearchReq;
import com.mf.service.pageConfig.IBasicPageService;
import io.github.heollhai.common.result.Result;
import io.github.heollhai.common.utils.VerifyUtils;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;


/**
 * @author mf
 * @since 2024-12-19
 */
@RestController
@RequestMapping("basic/page/v1")
public class BasicPageController {
    @Resource
    private IBasicPageService pageService;

    @Operation(summary = "新增|编辑")
    @PostMapping("save")
    public Result<Boolean> save(@Valid @RequestBody() PageBoAddReq pageBoAddReq) {
        BasicPageBo pageBo = new BasicPageBo();
        BeanUtils.copyProperties(pageBoAddReq, pageBo);
        if (VerifyUtils.isEmpty(pageBo.getId())) {
            return Result.success(pageService.save(pageBo));
        }
        return Result.success(pageService.updateById(pageBo));
    }

    @Operation(summary = "删除")
    @GetMapping("delete/{id}")
    public Result<Boolean> delete(@PathVariable("id") Integer id) {
        return Result.success(pageService.removeById(id));
    }

    @Operation(summary = "查询")
    @PostMapping("findPageList")
    public Result<Page<BasicPageBo>> findPageList(@RequestBody PageBoSearchReq pageBoSearchReq) {
        return Result.success(pageService.findPageList(pageBoSearchReq));
    }
}
